package de.poketradeshop.ui.controller;

import java.io.Serializable;
import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;






import de.poketradeshop.database.DatabaseService;
import de.poketradeshop.ui.model.Order;
import de.poketradeshop.ui.model.OrderContainer;
import de.poketradeshop.ui.model.Pokemon;
import de.poketradeshop.ui.model.PokemonProperty;
import de.poketradeshop.ui.model.Product;
import de.poketradeshop.ui.model.ProductContainer;
import de.poketradeshop.ui.model.SpecialProductContainer;

@Named
@SessionScoped
public class SpecialProductController implements Serializable {

	@Inject
	private SpecialProductContainer specialProductContainer;

	@Inject
	private DatabaseService databaseService;
	
	@Inject
	private OrderContainer orderContainer;


	/**
	 * Set special product container for homepage
	 */
	public void ProductHome() {
		try {

			List<Product> allPokemons = databaseService.getProductHome();
			specialProductContainer.setProducts(allPokemons);
			
			for (int i = 0; i < orderContainer.getOrders().size(); i++) {
				Order check = orderContainer.getOrders().get(i);

				for (int j = 0; j < allPokemons.size(); j++) {
					if (check.getProductId() == allPokemons.get(j)
							.getProductId()) {
						allPokemons.get(j).setInBasket(true);
					}
				}
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
}
